<HTML>
 <HEAD>
  <TITLE>ExtJS支持的自定义事件</TITLE>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  <link rel="stylesheet" type="text/css" href="../../ext-4.0/resources/css/ext-all.css" />
  <script type="text/javascript" src="../../ext-4.0/bootstrap.js"></script>
  <script type="text/javascript" src="../../ext-4.0/locale/ext-lang-zh_CN.js"></script>
	<script type="text/javascript">
		//创建Person类
		var Person = Ext.extend(Ext.util.Observable,{
			constructor : function(name){
			   this.name = name;
			   this.sayNum = 0;
			   this.say = function(){
					if(this.sayNum < 2){
						this.sayNum += 1;
						alert('I am '+name);
					}else{
						this.sayNum = 0;//触发自定义事件后计数器归零
						this.fireEvent('onSay',this);//激发自定义事件
					}
			   }
			   this.addEvents({//加入自定义事件
				  "onSay" : true
			   });
			}
		});
		var per = new Person('tom');//创建对象
		//为自定义事件绑定处理函数
		per.addListener('onSay',function handler(){
			alert('发生了自定义事件');
		});
	</script>
 </HEAD>
 <BODY>
	<input type='button' value='say' onclick='per.say()'>
 </BODY>
</HTML>
